package practice.design.factory;

/** 工厂模式 */
public class AnimalFactory {

    //基础版工厂写法
    public Animal creat(String type){
        if ("dog".equals(type)){
            return new Dog();
        }
        if ("cat".equals(type)){
            return new Cat();
        }
        if ("fish".equals(type)){
            return new Fish();
        }
        return null;
    }


    //升级版
    public static Animal creatSuper(Class<? extends Animal> clazz) throws Exception{
        if (clazz != null){
            return clazz.newInstance();
        }
        return null;
    }
}
